package pl.edu.mimuw.irs.rcp.view.figure;

import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Pattern;
import org.eclipse.swt.widgets.Display;

public class PlaceShape extends Ellipse {
	
	// *** Attributes

	// *** Methods

	@Override
	protected void fillShape(Graphics graphics) {
		Display display = Display.getCurrent();
		Rectangle boundingRect = getBounds();
		DoubleGradient doubleGradient = getDoubleGradient();
		
		Point top = boundingRect.getTop();
		Point middle = boundingRect.getCenter();
		Point bottom = boundingRect.getBottom();
		
		graphics.setAntialias(SWT.ON);
		graphics.setAlpha(127);
		
		Pattern pattern = new Pattern(display, top.x, top.y, middle.x, middle.y,
				doubleGradient.getTop(), doubleGradient.getUpperMiddle());
		graphics.setBackgroundPattern(pattern);
		graphics.fillArc(boundingRect, 0, 180);
		pattern.dispose();
		
		pattern = new Pattern(display, middle.x, middle.y, bottom.x, bottom.y,
				doubleGradient.getLowerMiddle(), doubleGradient.getBottom());
		graphics.setBackgroundPattern(pattern);
		graphics.fillArc(boundingRect, 180, 180);
		
		graphics.setBackgroundPattern(null);

		graphics.setAntialias(SWT.OFF);
		graphics.setAlpha(255);
		
		pattern.dispose();
	}
	
	protected DoubleGradient getDoubleGradient() {
		return DoubleGradient.SILVER;
	}

	@Override
	protected void outlineShape(Graphics graphics) {
		graphics.setAntialias(SWT.ON);
		super.outlineShape(graphics);
		graphics.setAntialias(SWT.OFF);
	}
	
}
